package com.webapi.common.utils;

import java.util.Date;
import java.util.concurrent.atomic.AtomicInteger;

public class CommonUtils {

    private static AtomicInteger autoNum = new AtomicInteger();
    private static String today = DateUtils.getDateFormat(DateUtils.DATE_SHORT_NO).format(new Date());

    public static String generateOrderCd() {
        toZero();
        StringBuilder sb = new StringBuilder();
        sb.append("F");
        sb.append(today);
        for (int i = autoNum.toString().length(); i <= 4; i++) {
            sb.append("0");
        }
        sb.append(autoNum.get());
        return sb.toString();
    }

    private static void toZero() {
        String now = DateUtils.getDateFormat(DateUtils.DATE_SHORT_NO).format(new Date());
        if (!today.equals(now)) {
            today = now;
            autoNum.set(0);
        }
    }
    
    public static void main(String[] args) {
        System.out.println(System.nanoTime());
    }
}
